import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadDemo1 {
    //标准库中的线程池
    public static void main(String[] args) {
        //创建单个线程的线程池
       // ExecutorService pool2=Executors.newSingleThreadExecutor();
        //创建线程数目动态增长的线程池
        //ExecutorService pool1=Executors.newCachedThreadPool();
        //创建了一个可以放下10个线程的线程池
        ExecutorService pool= Executors.newFixedThreadPool(10);
        for (int i = 0; i <10 ; i++) {
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.print("hello ");
                }
            });
        }
    }
    //标准库中定时器
    public static void main1(String[] args) {
        Timer timer=new Timer();
        timer.schedule((new TimerTask() {
            @Override
            public void run() {
                System.out.println("加油每一天");
            }
        }),3000);
        System.out.println("你好");
    }
}
